;(function () {
  new Vue({
    el: '#houseSharingInfo',
    data: {
      data: {projectInfo: {units: [], wps: [], stops: []}},
      unitId: '',
      unitDetailsFlag: false
    },
    methods: {
      getData () {
        hlhttp.get({
          url: 'customer/house_resource',
          data: {house_share_id: hlUrlUtil.GetQueryString('id')},
          success: (data) => {
            this.data = data
            this.$refs.contentInfo.innerHTML = data.contentDetail
          }
        })
      },
      routerPreview () {
        hlUrlUtil.goTo('hosuePreview', {id: hlUrlUtil.GetQueryString('id'), ddtab:true})
      },
      // 获取单元详情
      getUnitDetails:function(unitId){
        var self = this;
        self.unitId = unitId;
        self.unitDetailsFlag = true;
      },
      closeUnitPop:function(state){
        this.unitId = null;
        this.unitDetailsFlag = false;
      },
      editHouseSharing () {
        hlUrlUtil.goTo('houseEdit', {id: hlUrlUtil.GetQueryString('id'), ddtab:true})
      }
    },
    computed: {
      units () {
        let units = this.data.projectInfo.units;
        let buildingList = hlArrayUtil.removeRepeat(units, 'floorId');
        buildingList.map(item => {
          item.children = []
        })
        units.map(item => {
          buildingList.map(item0 => {
            if (item.floorId == item0.floorId) {
              item0.children.push({unitName: item.unitName, unitId: item.unitId, unitAcreage: item.unitAcreage, unitId: item.unitId})
            }
          })
        })
        return buildingList
      },
      unitsTotal () {
        let units = this.data.projectInfo.units;
        let acreage = 0
        units.map(item => {
          acreage += Number(item.unitAcreage)
        })
        return acreage
      },
      stops () {
        let stops = this.data.projectInfo.stops;
        let stopsList = hlArrayUtil.removeRepeat(stops, 'unitId');
        stopsList.map(item => {
          item.children = []
        })
        stops.map(item => {
          stopsList.map(item0 => {
            if (item.unitId == item0.unitId) {
              item0.children.push({positionName: item.stopName})
            }
          })
        })
        return stopsList
      },
      wps () {
        let wps = this.data.projectInfo.wps;
        let wpsList = hlArrayUtil.removeRepeat(wps, 'unitId');
        wpsList.map(item => {
          item.children = []
        })
        wps.map(item => {
          wpsList.map(item0 => {
            if (item.unitId == item0.unitId) {
              item0.children.push({positionName: item.wpName})
            }
          })
        })
        return wpsList
      }
    },
    mounted () {
      this.getData()
    }
  })
} ())
